import React from 'react';
import useTable from "@/cms/use/useTable";
import {Button, message, Modal, Space, Switch, Tag} from "antd";
import useAddEdit from "./useAddEdit";
import dayjs from "dayjs";

function TeaRoom(props) {

    const {queryList,tableDOM} = useTable({
        columns:[
            {
                title:"售价",
                dataIndex:"price",
            },{
                title:"到账金额",
                dataIndex:"amount"
            }, {
                title: "创建时间",
                dataIndex: "CreatedAt",
                render(text){
                    return dayjs(text).format("YYYY-MM-DD HH:mm:ss")
                }
            },{
                title:"操作",
                render(_,record){
                    return <Space>
                        {/*<a onClick={()=>setOpen?setOpen(record):""}>编辑</a>*/}
                        <a style={{color:"red"}} onClick={()=>remove(record)}>删除</a>
                    </Space>
                }
            }
        ],
        xhr:{
            query:"/app/vipList"
        }
    })

    const {ModalDOM,setOpen} = useAddEdit({
        queryList
    })
    function changeStatus(checked,record){
        let status = 0;
        if (checked){
            status=3
        }else{
            status=1
        }
        ax.post("/api/modifyRoom",{
            id:record.ID,
            status
        }).then(res=>{
            if (res.msg === "success"){
                queryList()
            }
        })
    }
    function remove(record){
        Modal.confirm({
            title:"确认要删除吗？",
            onOk(){
                return new Promise((resolve, reject) => {
                    ax.post("/api/deleteVipSetting",{
                        id:record.ID
                    }).then(res=>{
                        message.success(res.msg);
                        queryList({
                            current:1
                        });
                        resolve()
                    }).catch(err=>{
                        reject(err)
                    })
                })
            }
        })
    }
    return (
        <div>
            {ModalDOM}
            <Button type={"primary"} onClick={()=>setOpen(true)}>添加</Button>
            {tableDOM}
        </div>
    );
}

export default TeaRoom;